<template>
  <view class="service-item" @click="onServiceClick">
    <view class="service-item__top">
      <image :src="service.image" mode="aspectFill" class="service-item__image" />
      <view 
        v-if="service.tag" 
        class="service-item__tag"
        :style="{backgroundColor: service.tagColor || '#ff6b6b'}"
      >
        {{ service.tag }}
      </view>
      <view v-else-if="service.hot" class="service-item__tag">热门</view>
    </view>
    <view class="service-item__title">{{ service.title }}</view>
    <view class="service-item__info">
      <text class="service-item__price">{{ service.price }}</text>
      <text class="service-item__sales">{{ service.sales }}人已下单</text>
    </view>
  </view>
</template>

<script setup>
const props = defineProps({
  service: {
    type: Object,
    required: true
  }
});

const emit = defineEmits(['click']);

const onServiceClick = () => {
  emit('click', props.service.id);
};
</script>

<style lang="scss" scoped>
.service-item {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background-color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  
  &__top {
    position: relative;
    width: 100%;
    height: 100px;
  }
  
  &__image {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
  
  &__tag {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 12px;
    color: #ffffff;
    background-color: #ff6b6b;
    padding: 2px 6px;
    border-radius: 4px;
  }
  
  &__title {
    padding: 8px 10px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  &__info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px 10px;
  }
  
  &__price {
    font-size: 15px;
    font-weight: bold;
    color: #ff6b6b;
  }
  
  &__sales {
    font-size: 12px;
    color: #999;
  }
}
</style>
